#!/bin/bash
# 
# File: stop.sh
# Purpose: stop autossh for tunnel sites
#

cd $(dirname "$0")
. ./common.sh

INSTALLDIR=$(cd "$(dirname "$0")"; pwd);
PID_SCREEN_SCRIPT=$INSTALLDIR/pid-screen.sh

test "$1" && tunnelsites="$@" || tunnelsites=$(./sites.sh)

for tunnelsite in $tunnelsites; do
	
    tunnel_name=`echo ${tunnelsite} | cut -d = -f 1`;
	
	info shutdown $tunnel_name ...	
    pids=$(screen -ls | grep -w $tunnel_name | cut -d '.' -f 1);	
    for pid in $pids; do
        kill -9 $pid;
		info kill $pid success
	done
    screen -S $tunnel_name -wipe >/dev/null || :
	
done
